package com.lanxin.oa.login.controller;
import com.lanxin.bean.ZzAccount;
import com.lanxin.oa.login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/login")
public class LoginController {

	@Autowired
	private  LoginService loginService;
	
	@RequestMapping("/denglu")
	public ModelAndView denglu(String username,String password,HttpSession session){
		ModelAndView mv=new ModelAndView();
		if(username!=null && !username.equals("")){
		ZzAccount account=loginService.loginService(username, password);
		if(account!=null){
			System.out.println(account.getInactive());
			if(account.getInactive()!=null && account.getInactive().equals("q")){
				String empname=account.getEmployee().getEmpName();
				Integer empid=account.getEmployee().getOid();
				mv.setViewName("../view/index.jsp");
				session.setAttribute("empname", empname);
				session.setAttribute("empid", empid);
				String zhanghao=account.getUsername();
				session.setAttribute("zhanghao", zhanghao);
//				//权限
//				List path=loginService.selectEmp_Role_function(empid);
//				List pathAll=loginService.selectAllEmp_Role_function();
//				session.setAttribute("path", path);
//				session.setAttribute("pathAll", pathAll);
				return mv;
				
			}
			else{
				mv.addObject("error","账号已被禁用");
				mv.setViewName("../view/login/login.jsp");
				return mv;
			}
		}
		else{
			mv.addObject("error","账号不存在");
			mv.setViewName("../view/login/login.jsp");
			return mv;
		}
		}else{
			mv.addObject("message","账号输入不合法");
			mv.setViewName("../view/login/login.jsp");
			return mv;
		}
		
	}
}
